package com.jinlejia.erp.ui.mine.process;


import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.WindowManager;

import androidx.recyclerview.widget.RecyclerView;

import com.jinlejia.erp.R;
import com.jinlejia.erp.utils.DisplayUtil;


/**
 * 左右边线
 */

public class LeftAndRightTagDecoration extends RecyclerView.ItemDecoration {
    private int tagWidth;
    private int outWidth;
    private Paint leftPaint;
    private Paint rightPaint;
    private float last;
    public int mWidth;
    public int mHight;
    private Context context;

    public LeftAndRightTagDecoration(Context context) {
        this.context = context;
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        DisplayMetrics outMetrics = new DisplayMetrics();
        wm.getDefaultDisplay().getMetrics(outMetrics);
        mWidth = DisplayUtil.dip2px(context, outMetrics.widthPixels);
        mHight = DisplayUtil.dip2px(context, outMetrics.heightPixels);


        //----width----->1440----height----->2368  圆环距离外部 16.5dp

        leftPaint = new Paint();
        leftPaint.setColor(context.getResources().getColor(R.color.colorDivider));
        tagWidth = context.getResources().getDimensionPixelSize(R.dimen.tag_width);
        outWidth = context.getResources().getDimensionPixelSize(R.dimen.out_width);
    }

    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
        super.getItemOffsets(outRect, view, parent, state);
        outRect.left = outWidth;
    }

    @Override
    public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
        super.onDraw(c, parent, state);
        int childCount = parent.getChildCount();
        for (int i = 0; i < childCount; i++) {
            View child = parent.getChildAt(i);
            float left = child.getLeft() + DisplayUtil.dip2px(context, 20);
            float right = left + tagWidth;
            float top = child.getTop() + DisplayUtil.dip2px(context, 28);
            float bottom = child.getBottom() + DisplayUtil.dip2px(context, 17);
            if (childCount != 1) {
                if (i == childCount - 1) {
                    return;
                }
            }
            c.drawRect(left, top, right, bottom, leftPaint);
        }
    }

}
